import {
    Entity,
    PrimaryGeneratedColumn,
    Column,
    CreateDateColumn,
    UpdateDateColumn,
    ManyToOne,
    JoinColumn
} from 'typeorm';
import { User } from '../../users/entities/user.entity';

export type KycStatus = 'pending' | 'approved' | 'rejected' | 'expired';
export type KycType = 'individual' | 'corporate';

@Entity('kyc_submissions')
export class KycSubmission {
    @PrimaryGeneratedColumn()
    id: number;

    @ManyToOne(() => User, (user) => user.kycSubmissions, { eager: true })
    @JoinColumn({ name: 'user_id' })
    user: User;

    @Column({ type: 'enum', enum: ['individual', 'corporate'], default: 'individual' })
    type: KycType;

    @Column({ type: 'enum', enum: ['pending', 'approved', 'rejected', 'expired'], default: 'pending' })
    status: KycStatus;

    // 个人信息
    @Column({ nullable: true })
    fullName?: string;

    @Column({ nullable: true })
    idNumber?: string;

    @Column({ nullable: true })
    country?: string;

    @Column({ nullable: true })
    dateOfBirth?: Date;

    // 企业信息
    @Column({ nullable: true })
    companyName?: string;

    @Column({ nullable: true })
    registrationNumber?: string;

    @Column({ nullable: true })
    businessAddress?: string;

    // 文件存储（JSON格式存储文件路径）
    @Column({ type: 'json', nullable: true })
    documents?: {
        idCard?: string;
        passport?: string;
        proofOfAddress?: string;
        businessLicense?: string;
        [key: string]: string | undefined;
    };

    @Column({ type: 'text', nullable: true })
    comment?: string;

    @Column({ nullable: true })
    reviewedAt?: Date;

    @CreateDateColumn()
    createdAt: Date;

    @UpdateDateColumn()
    updatedAt: Date;
}
